package com.jh3502.vivo.function.travel;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.RadioGroup;
import android.widget.TabHost;
import android.widget.TabWidget;
import android.widget.TextView;

import com.jh3502.vivo.R;
import com.jh3502.vivo.base.BaseActivity;
import com.jh3502.vivo.base.BasePresenter;
import com.jh3502.vivo.function.travelnew.TravelNewActivity;
import com.jh3502.vivo.utils.Utils;

import butterknife.BindView;

/**
 * @author harisucici
 * @version 2018/11/26 11:49
 * name
 * todo
 * @email harisucici@gmail.com
 */
public class TravelListActivity extends BaseActivity {
    @BindView(R.id.toolbar_title)
    TextView toolbarTitle;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(android.R.id.tabs)
    TabWidget tabs;
    @BindView(android.R.id.tabcontent)
    FrameLayout tabcontent;
    @BindView(android.R.id.tabhost)
    TabHost tabHost;
    @BindView(R.id.travel_radio)
    RadioGroup travelRadio;
    int[] radioButton = {R.id.radioButton1, R.id.radioButton2};
    private String[] tabMenu = {"我发起的", "我审批的"};

    @Override
    public BasePresenter initPresenter() {
        return null;
    }

    @Override
    protected int setViewId() {
        return R.layout.activity_travel_list;
    }

    @Override
    protected void initView() {
        toolbar.setTitle("");
        toolbarTitle.setText("出差");
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);


        tabHost.setup();

        TabHost.TabSpec tab1 = tabHost.newTabSpec("tab1")
                .setIndicator(tabMenu[0])
                .setContent(R.id.content_tab1);
        tabHost.addTab(tab1);

        TabHost.TabSpec tab2 = tabHost.newTabSpec("tab2")
                .setIndicator(tabMenu[1])
                .setContent(R.id.content_tab2);
        tabHost.addTab(tab2);

        tabHost.setCurrentTabByTag(tabMenu[0]);
        travelRadio.check(radioButton[0]);
        updateTab(tabHost);

        tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
            @Override
            public void onTabChanged(String tabId) {
                updateTab(tabHost);
            }
        });

    }

    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_note, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                onBackPressed();
                break;
            case R.id.action_note:
                Utils.getInstance().startActivity(this, TravelNewActivity.class);
                break;
            default:
        }
        return true;
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void doOnDestroy() {

    }

    @Override
    protected void doOnResume() {

    }

    @Override
    protected void doOnSaveInstanceState(Bundle savedInstanceState) {

    }

    @Override
    public void responseError(int code, String msg) {

    }

    private void updateTab(final TabHost tabHost) {
        for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
            View view = tabHost.getTabWidget().getChildAt(i);
            TextView tv = tabHost.getTabWidget().getChildAt(i).findViewById(android.R.id.title);
            tv.setTextSize(16);
            if (tabHost.getCurrentTab() == i) {
//                view.setBackground(ContextCompat.getDrawable(this,R.drawable.point_red));
                tv.setTextColor(Color.WHITE);
                travelRadio.check(radioButton[i]);
            } else {
                tv.setTextColor(Color.parseColor("#99c4ff"));
            }

        }

    }
}
